<?php

namespace app\admin\controller;

use think\Controller;
use app\common\model\PicTypes as M;

//广告位类别
class Pictypes extends Controller {

    //图片列表
    public function index() {
        return $this->fetch();
    }

    //类别josn数据
    public function getpictype_josn() {
        $m = new M();
        $pictype = $m->getPicType();
        $lists = ['code' => 0, 'msg' => '', 'data' => []];
        foreach ($pictype as $k => $v) {
            $lists['data'][] = $v;
        }
        return $lists;
    }

    //图片类别修改页面
    public function edit() {
        $p = new M();
        $s = $p->getById(input('id'));
        $this->assign('id', $s->id);
        $this->assign('s', $s);
        return $this->fetch();
    }

    //图片类别添加页面
    public function add() {
        return $this->fetch();
    }

    //图片类别添加或修改
    public function pictype_submit() {
        $p = new M();
        if (input('id', 0) == 0) {
            $opt = [
                'name' => input('name'), //名称
                'note' => input('note'), //备注
            ];
            $rs = $p->add($opt);
            //日志
            $id = $p->order("id desc")->find();
            $name = session('my_self')['name'];
            $des = $name . "【添加】了编号为【" . $id->id . "】的图片类别";
            add_log(2, session('my_self')['id'], $des);
            return js_return($rs[0], $rs[1]);
        } else {
            $opt = [
                'name' => input('name'), //名称
                'note' => input('note'), //副名称
            ];
            $rs = $p->modify($opt, input('id'));
            //日志
            $id = input('post.id');
            $name = session('my_self')['name'];
            $des = $name . "【修改】了编号为【" . $id . "】的图片类别";
            add_log(2, session('my_self')['id'], $des);
            return js_return($rs[0], $rs[1]);
        }
    }

    //图片类别删除
    public function del_submit() {
        $p = new M();
        $p->del();
        $id = input('id');
        $name = session('my_self')['name'];
        $des = $name . "【删除】了编号为【" . $id . "】的图片类别";
        add_log(2, session('my_self')['id'], $des);
        $this->success('新增成功', 'Pictype/');
    }

}
